/*
 * DirectoryReaderLinked.h
 *
 *  Created on: Mar 26, 2010
 *      Author: Lukasz Spintzyk
 */

#ifndef DIRECTORYREADERLINKED_H_
#define DIRECTORYREADERLINKED_H_

#include "DirectoryReader.h"
class DirEntry;

class DirectoryReaderLinked: public DirectoryReader {
public:
	DirectoryReaderLinked(BlockManager& b, InodeManager& i);
	virtual ~DirectoryReaderLinked();


	/*
	 * \throw FSException
	 */
	virtual InodePtr path2Inode(const std::string& path);

	virtual void setUpRootDirectory(uint16_t uid, uint16_t gid);
	virtual void setUpDirectory(InodePtr inode, uint32_t parent_inode_num);

	virtual void addDirEntry(DirEntry& e, InodePtr);


	virtual boost::shared_ptr<DirectoryIterator> begin(InodePtr inode);

protected:
	InodePtr entryNameInParentDir2Inode(InodePtr parentDir,const std::string& entry_name);

private:
	virtual InodePtr relPath2Inode(const uint32_t dir_inode, const std::string& relative_path);


	/*!
	 * Function returns last dir entry in directory pointed by inode.
	 * \param inode - inode on which function operates
	 * \param last - output parameter with last DirEntry
	 * \return position ind_buffer where last starts.
	 */
	uint32_t findLastEntry(InodePtr inode, DirEntry& last);

	byte* d_buffer;
};

#endif /* DIRECTORYREADERLINKED_H_ */
